#!/usr/bin/env python3
#__auth__:fonzie
#Company:XMZJ
#Email:fangqi@xiaomai5.com

import json

from tornado.web import RequestHandler, StaticFileHandler
#from utils.session import Session

class BaseHandler(RequestHandler):
    @property
    def db(self):
        """作为RequestHandler对象的db属性"""
        return self.application.db

    def prepare(self):
        """预解析json数据"""
        if self.request.headers.get("Content-Type", "").startswith("application/json"):
            self.json_args = json.loads(self.request.body)
        else:
            self.json_args = {}

class StaticFileBaseHandler(StaticFileHandler):
    '''自定义静态文件处理类，在用户获取html时设置_xsrf的cookie'''
    def __init__(self, *args, **kwargs):
        super(StaticFileHandler, self).__init__(*args, **kwargs)
        self.xsrf_token